package cn.t12.qg.orderprovider.service;

import cn.t12.qg.orderprovider.mapper.QgOrderMapper;
import cn.t12.qg.service.user.OrderService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qg.pojo.QgOrder;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService(version = "1.0.0", interfaceClass = OrderService.class)
public class QgOderServiceImpl implements OrderService {

    @Autowired
    private QgOrderMapper qgOrderMapper;

    @Override
    public boolean saveOrder(QgOrder qgOrder) {
        return qgOrderMapper.insert(qgOrder) > 0;
    }

    @Override
    public List<QgOrder> listOrderByUserId(String userId) {
        QueryWrapper<QgOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        return  qgOrderMapper.selectList(wrapper);
    }

    @Override
    public QgOrder getByOrderNo(String orderNo) {
        QueryWrapper<QgOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no", orderNo);
        return  qgOrderMapper.selectOne(wrapper);
    }
}
